<?php
	####################################################
	# library import and object instance.              #
	####################################################
	# 커먼 인클루드
	include_once( '../common.php' );

	####################################################
	# request data($_POST AND $_GET FROM $_REQUEST)    #
	####################################################
	# REQUEST(get and post variables)
	//$req = $_REQUEST;

	//$req = Request::clean_request($_REQUEST, 1);

	# GET(url variables)

	# POST(form variables)
	$pmode = Request::clean_individual($_POST['mode']);
	$preturl = Request::clean_individual($_POST['returl']);
	//Nlog::puts('pmode',$pmode);
	//Nlog::puts('preturl',$preturl);
	//$pdic = NForm::dictionary($p, 'puid');


	# Validation(special case validate)
	//*/
	Validation::check_is_emptys($pmode);
	Validation::check_is_emptys($preturl);
	//*/
	####################################################
	# implementation                                   #
	####################################################
	$sec->individual_access();
	$sec->run_cookie_check();

	switch($pmode) {
		case "modify":
			$pmap = Request::dic($_POST['map'], 'puid');
			$cnt = $appm->modify_packages($pmap);
		break;

		case "modifykey":
			$pmap = Request::dic($_POST['map'], 'puid');
			//Nlog::xmp($pmap);
			foreach($pmap as $key=>$val){
				$pifarr = explode('.',$val['packages_init_file']);
				if(!empty($pifarr[3])){
					Mover::back("확장자를 입력하지 마십시오.", TRUE);
				}
				if(!empty($val['param'])){
					if(!strstr($val['param'],'?')){
						Mover::back("기본 파라메터에 쿼리스트링에 유요한 '?'값을 포함 하여야 합니다.\\n\\n예제)?key=val&foo=bar", TRUE);
					}
				}
			}
			$cnt = $appm->modify_packages_key($pmap);
		break;

		case "create":
			//Nlog::puts($_POST['map']);
			$pmap = Request::clean_request($_POST['map']);
			//Nlog::puts($pmap);
			Validation::check_is_emptys($pmap['package_filename']);
			$cnt = $appm->create_packages($pmap);
		break;

		case "delete":
			$pmap = Request::dic($_POST['map'], 'puid');
			$cnt = $appm->delete_packages($pmap);
		break;

		default : break;
	} //endswitch


?>
<?php
	# HTML START
	echo $html->custom_header(TITLE);
	echo $tplt->page_construct_javascript();
	echo $html->custom_js("{$JS}common.js");
	echo $html->custom_css("{$CSS}common.css");
	echo $html->custom_body();
?>
	<?php $tplt->app_head($NAVI)?>
	<?php $tplt->tiles_admin_sidebar($NAVI)?>
	<?php $tplt->tiles_admin_contents($pkname, $pname, $pdesc)?>


	<div class="msgbox">
		<p>
			<?php switch($pmode) :
				case "modify" : ?>
					<strong>패키지 정보 수정 내역</strong><br />
					<?=$cnt?>개의 패키지 정보가 수정 되었습니다.
				<?php break; ?>

				<?php case "modifykey" : ?>
					<strong>패키지키 정보 수정 내역</strong><br />
					<?=$cnt?>개의 패키지키 정보가 수정 되었습니다.
				<?php break; ?>

				<?php case "create": ?>
					<strong>패키지 추가 내역</strong><br />
					<?=$cnt?>개의 패키지가 추가 되었습니다.
				<?php break; ?>

				<?php case "delete": ?>
					<strong>패키지 삭제 내역</strong><br />
					<?=$cnt?>개의 패키지가 삭제 되었습니다.
				<?php break; ?>

				<?php default : break; ?>
			<?php endswitch; ?>
		</p>
	</div>
	<span class="cbtn_s mart5" onclick="Mover.href('<?=$preturl?>');">확인</span>


<?php
	# HTML END
	echo $tplt->tiles_admin_footer();
	echo $tplt->page_destruct_javascript();
	include_once( '../endproc.php' );
	echo $html->html_footer();
?>